package com.lecyon.farm.controller;

import com.lecyon.farm.base.BaseRequestVo;
import com.lecyon.farm.base.RestResponse;
import com.lecyon.farm.service.IFmCarService;
import com.lecyon.farm.service.impl.BigScreenDataService;
import com.lecyon.farm.vo.data.DeviceAccessStatisticsVo;
import com.lecyon.farm.vo.data.WorkVolumeByArea;
import com.lecyon.farm.vo.data.WorkVolumeByType;
import com.lecyon.farm.vo.data.WorkVolumeByTypeAndArea;
import com.lecyon.farm.vo.query.QueryFmCarVo;
import com.lecyon.farm.vo.query.QueryFmWorkDetailsVo;
import com.lecyon.farm.vo.query.QueryFmWorkVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author Yao Zheng
 * @Date 2020/5/18 19:58
 */
@RestController
@RequestMapping("/screen")
@Api(tags = "农机作业")
@ResponseBody
@CrossOrigin
public class BigScreenController {

    private BigScreenDataService bigScreenDataService;

    @Autowired
    public BigScreenController(BigScreenDataService bigScreenDataService, IFmCarService fmCarService) {
        this.bigScreenDataService = bigScreenDataService;
    }

    @ApiOperation(value = "查询所有作业类型", notes = "查询所有作业类型，author:YaoZheng")
    @PostMapping(value = "/work-type/getList")
    public List<String> getWorkTypeList(@RequestBody @Valid BaseRequestVo<QueryFmWorkVo> vo) {
        return bigScreenDataService.getAllWorkType(vo);
    }

    @ApiOperation(value = "按作业类型统计", notes = "按作业类型统计，author:YaoZheng")
    @PostMapping(value = "/statistic/type")
    public RestResponse<List<WorkVolumeByType>> statisticsByType(@RequestBody @Valid BaseRequestVo<QueryFmWorkVo> vo) {
        return bigScreenDataService.getTotalWorkDataGroupByWorkType(vo);
    }

    @ApiOperation(value = "查询下辖所有区域", notes = "查询下辖所有区域，author:YaoZheng")
    @PostMapping(value = "/area/getList")
    public RestResponse<List<String>> getAreaList(@RequestBody @Valid BaseRequestVo<QueryFmWorkVo> vo) {
        return bigScreenDataService.getAllAreaName(vo);
    }

    @ApiOperation(value = "按区域统计", notes = "按区域统计，author:YaoZheng")
    @PostMapping(value = "/statistic/area")
    public RestResponse<List<WorkVolumeByArea>> statisticsByArea(@RequestBody @Valid BaseRequestVo<QueryFmWorkVo> vo) {
        return bigScreenDataService.getTotalWorkDataGroupByArea(vo);
    }

    @ApiOperation(value = "按区域以及作业类型统计", notes = "按区域以及作业类型统计，author:YaoZheng")
    @PostMapping(value = "/statistic/area_type")
    public RestResponse<List<WorkVolumeByTypeAndArea>> statisticsByAreaAndType(@RequestBody @Valid BaseRequestVo<QueryFmWorkVo> vo) {
        return bigScreenDataService.getWorkQuantityByTypeAndArea(vo);
    }

    @ApiOperation(value = "统计一周详情", notes = "统计一周详情，author:YaoZheng")
    @PostMapping(value = "/statistic/week")
    public RestResponse<List<BigDecimal>> statisticsByWeek(@RequestBody @Valid BaseRequestVo<QueryFmWorkVo> vo) {
        return bigScreenDataService.getWorkQuantityDataByWeek(vo);
    }

    @ApiOperation(value = "设备分布统计", notes = "设备分布统计，author:YaoZheng")
    @PostMapping(value = "/statistic/device")
    public RestResponse<List<DeviceAccessStatisticsVo>> statisticsDevice(@RequestBody @Valid BaseRequestVo<QueryFmCarVo> vo) {
        return bigScreenDataService.statisticsDevice(vo);
    }

    @ApiOperation(value = "昨日地块数", notes = "昨日地块数，author:YaoZheng")
    @PostMapping(value = "/statistic/fm-detail/count")
    public RestResponse<List<Integer>> getAreaFmDetailCountYesterday(@RequestBody @Valid BaseRequestVo<QueryFmWorkDetailsVo> vo) {
        return bigScreenDataService.getAreaFmWorkDetailCountYesterday(vo);
    }

    @ApiOperation(value = "昨日作业量", notes = "昨日作业量，author:YaoZheng")
    @PostMapping(value = "/statistic/fm-work/total")
    public RestResponse<List<BigDecimal>> getTotalWorkQuantityByAreaYesterday(@RequestBody @Valid BaseRequestVo<QueryFmWorkVo> vo) {
        return bigScreenDataService.getTotalWorkQuantityByAreaYesterday(vo);
    }

    @ApiOperation(value = "昨日活动主机数量", notes = "昨日活动主机数量，author:YaoZheng")
    @PostMapping(value = "/statistic/active-device/count")
    public RestResponse<List<Integer>> getActiveDeviceCountYesterday(@RequestBody @Valid BaseRequestVo<QueryFmWorkDetailsVo> vo) {
        return bigScreenDataService.getActiveDeviceCountYesterday(vo);
    }

}
